// components/index/funcs/funcs.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    blocks: [
      {
        index: 0,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/searchbook.svg',
        title: '查找书籍',
        url: '/pages/searchBook/searchBook'
      },
      {
        index: 1,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/book_white_48dp.svg',
        title: '我的书籍',
        url: '/pages/myBook/myBook'
      },
      {
        index: 2,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/comment_bank_white_48dp.svg',
        title: '我的评论',
        url: '/pages/myComment/myComment'
      },
      {
        index: 3,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/searchgroup.svg',
        title: '查找学习组',
        url: '/pages/searchGroup/searchGroup'
      },
      {
        index: 4,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/supervised_user_circle_white_48dp.svg',
        title: '我的学习组',
        url: '/pages/myGroup/myGroup'
      },
      {
        index: 5,
        icon: 'https://6d79-my-book-assist-7gc4zqa8552557ed-1305224861.tcb.qcloud.la/images/icons/account_circle_white_48dp.svg',
        title: '个人信息',
        url: '/pages/myInfo/myInfo'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleNav (e) {
      const index = e.currentTarget.dataset.index
      // 点击了查找书籍，直接切换 tab 即可
      if (index === 0) {
        // 传值给 父组件
        this.triggerEvent('PageChange', {
          isTabbarShow: true,
          curIndex: 1,
          curTab: 'book'
        })
      } else if (index === 1) {
        wx.navigateTo({
          url: '/pages/myBook/myBook'
        })
      } else if (index === 2) {
        wx.navigateTo({
          url: '/pages/myComment/myComment'
        })
      } else if (index === 3) {
        // 传值给 父组件
        this.triggerEvent('PageChange', {
          isTabbarShow: true,
          curIndex: 2,
          curTab: 'group'
        })
      } else if (index === 4) {
        wx.navigateTo({
          url: '/pages/myGroup/myGroup'
        })
      } else if (index === 5) {
        this.triggerEvent('PageChange', {
          isTabbarShow: true,
          curIndex: 2,
          curTab: 'user'
        })
      }
    }
  }
})
